package com.cgt.web.service.impl;

import com.cgt.web.dao.TeaDao;
import com.cgt.web.dao.impl.TeaDaoImpl;
import com.cgt.web.pojo.Teacher;
import com.cgt.web.service.TeaService;
import com.cgt.web.util.JDBCUtil;
import com.cgt.web.util.PageInfo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class TeaServiceImpl implements TeaService {
    TeaDao teaDao = new TeaDaoImpl();
    @Override
    public List<Teacher> selectAll() {
        return teaDao.selectAll();
    }

    @Override
    public void deleteById(String id) {
        teaDao.deleteById(id);
    }

    @Override
    public void addt(Teacher teacher) {
        teaDao.addt(teacher);
    }

    @Override
    public Teacher toUpdate(String id) {
        return teaDao.toUpdate(id);
    }

    @Override
    public void update(Teacher teacher) {
        teaDao.update(teacher);
    }

    @Override
    public PageInfo<Teacher> selectByPage(int pageNo, int pageSize) {
        int offset = (pageNo-1) * pageSize;
        List<Teacher> list = teaDao.selectByPage(offset,pageSize);
        int totalCount = teaDao.getTotalCount();
        int totalPage = (int)Math.ceil((double)totalCount/pageSize);
        PageInfo pageInfo = new PageInfo(list,pageNo,pageSize,totalPage);
        return pageInfo;
    }
}
